SUBSTR[ING]
Purpose
This function returns a substring of the length length
from the position position
, out of the string string
.
Syntax
substring::=
Usage notes
-
If
length
is not specified, all of the characters to the end of the string are used. -
If
position
is negative, counting begins at the end of the string. -
If
position
is 0 or 1, the result begins from the first character of the string. -
If
position
is before the start or after the end of the string, the result isNULL
. -
For additional information, refer to the functions RIGHT, LEFT, and REGEXP_SUBSTR.
-
MID is an alias for this function.
Example
SELECT SUBSTR('abcdef',2,3) S1,
SUBSTRING('abcdef' FROM 4 FOR 2) S2,
SUBSTR('abcdef',-3) S3,
SUBSTR('abcdef',7) S4,
SUBSTR('abcdef',-7) S5
;
Result:
S1 |
S2 |
S3 |
S4 |
S5 |
---|---|---|---|---|
bcd |
de |
def |
NULL |
NULL |